﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace ESMAM.Web.Core.Filters
{
    /// <summary>
    /// //http://www.cnblogs.com/guzhongx/p/filedownnotworking.html?utm_source=tuicool&utm_medium=referral
    /// 防止文件下载出现问题的 Filter
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
    public class FileFilter : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            var browserInfo = filterContext.RequestContext.HttpContext.Request.Browser.Browser;
            if (filterContext.Result is FileResult)
            {
                filterContext.HttpContext.Response.CacheControl = browserInfo == "IE" ? "private" : "no-cache";
            }
        }
    }
}
